Micron Document
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| SparkN0de-git | SparkN0de |
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


Commit 15513ee98e97c368c5b1c41714254e6e2db674b0


Parents : 01f5164
Author : Ivan <ivan@quad4.io>
Signature : Signature validation error
Date : 2026-05-01T04:10:08-05:00

test(WebSocketConnection): add test for handling invalid JSON frames without throwing errors

Changes

1 files changed, 19 insertions(+), 0 deletions(-)


Diff

diff --git a/tests/frontend/WebSocketConnection.test.js b/tests/frontend/WebSocketConnection.test.js
index 7a7424d1..fd0fe8e4 100644
--- a/tests/frontend/WebSocketConnection.test.js
+++ b/tests/frontend/WebSocketConnection.test.js
@@ -114,4 +114,23 @@ describe("WebSocketConnection module", () => {
WebSocketConnection.destroy();
});
+
+ it("forwards invalid JSON frames without throwing", async () => {
+ const MockWS = makeWsImpl();
+ global.WebSocket = MockWS;
+
+ const { default: WebSocketConnection } = await import("../../meshchatx/src/frontend/js/WebSocketConnection.js");
+
+ const onMessage = vi.fn();
+ WebSocketConnection.on("message", onMessage);
+
+ await WebSocketConnection.connect();
+ await vi.waitUntil(() => WebSocketConnection.ws?.readyState === MockWS.OPEN);
+
+ const sock = WebSocketConnection.ws;
+ expect(() => sock.onmessage({ data: "<<<not-json>>>" })).not.toThrow();
+ expect(onMessage).toHaveBeenCalledTimes(1);
+
+ WebSocketConnection.destroy();
+ });
});


──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────